import 'package:flutter/material.dart';

import '../../foundation/decoration/linear_gradient_decoration.dart';
import '../../foundation/style/bold_text_style.dart';
import '../container/separated_row.dart';

/// FileName section_header
///
/// @Author lax
/// @Date 2023/11/3
///
/// @Description

class SectionHeader extends StatelessWidget {
  static TextStyle? defaultTitleStyle;

  static EdgeInsets? defaultPadding = const EdgeInsets.symmetric(vertical: 16);

  static Widget? defaultLeftWidget = Container(
    width: 4,
    height: 16,
    decoration: LinearGradientDecoration(radius: 2),
  );

  final String? title;

  late final TextStyle? titleStyle;

  late final EdgeInsets padding;

  late final Widget? leftWidget;
  final Widget? rightWidget;
  late final Widget? separator;

  final bool showLeftWidget;

  SectionHeader({
    super.key,
    this.title,
    TextStyle? titleStyle,
    EdgeInsets? padding,
    Widget? leftWidget,
    this.rightWidget,
    this.separator = const SizedBox(width: 8),
    this.showLeftWidget = true,
  }) {
    this.titleStyle =
        titleStyle ?? defaultTitleStyle ?? BoldTextStyle(fontSize: 16);
    this.padding = padding ?? defaultPadding ?? EdgeInsets.zero;
    this.leftWidget = leftWidget ?? defaultLeftWidget;
  }

  @override
  Widget build(BuildContext context) {
    return SeparatedRow(
      separator: separator,
      padding: padding,
      children: [
        Visibility(
          visible: showLeftWidget && leftWidget != null,
          child: leftWidget ?? const SizedBox(),
        ),
        Expanded(
          child: Text(title ?? '', style: titleStyle),
        ),
        Visibility(
          visible: rightWidget != null,
          child: rightWidget ?? const SizedBox(),
        ),
      ],
    );
  }
}
